#include "mysql_header/mysqldatabase.h"

MySqlDatabase::MySqlDatabase(QString connectionName)
    : db(QSqlDatabase::addDatabase("QMYSQL", connectionName))
    , query(QSqlQuery(db))
{
    GlobalData* data = GlobalData::globalInstance();
    db.setHostName(data->getDataBaseHostName());
    db.setPort(data->getDataBasePort());
    db.setDatabaseName(data->getDataBaseName());
    db.setUserName(data->getDataBaseUserName());
    db.setPassword(data->getDataBasePassWord());
    if (!db.open()) {
        qDebug() << "dababase oepn error";
    }
    else {
        qDebug() << "[INFO] " + connectionName + " open";
    }
}

MySqlDatabase::~MySqlDatabase() {
    if (!db.isOpen()) {
        db.close();
    }
}
